from rest_framework.exceptions import ValidationError


def booking_date_range_filter(request, queryset):
    query = queryset
    params = request.query_params

    if 'start_date' in params and 'end_date' not in params:
        start_date = params['start_date']
        query = query.filter(start_date__date=start_date)

    elif 'start_date' in params and 'end_date' in params:
        start_date = params['start_date']
        end_date = params['end_date']

        if start_date > end_date:
            raise ValidationError(
                'Start date must be lower than end date.')
        query = query.filter(start_date__date__range=[start_date, end_date])

    return query